package com.java.day06.homework;

import java.util.Random;

/**
 * 创建一个父类：Hero ，属性有 名字，力量，智力，敏捷， 方法有 徒手攻击（攻击力=力量的上下百分之20）
 */


public class Hero {

    //名字
    private String name;

    //力量
    private double strength;

    //智慧
    private double wit;

    //敏捷
    private double agility;


    //构造方法

    //无参
    public Hero() {

    }

    //单参
    public Hero(String name) {
        this.name = name;
        this.strength = 100;
        this.wit = 100;
        this.agility = 100;
    }

    //全参
    public Hero(String name, double strength, double wit, double agility) {
        this.name = name;
        this.strength = strength;
        this.wit = wit;
        this.agility = agility;
    }

    //实例方法

    //徒手攻击
    public void unarmedAttack(){
        //攻击力
        double atack ;
        //随机数
        int num;
        Random random = new Random();
        num = random.nextInt(2);
        if(num>0){
            atack =this.strength+this.strength*0.2;
        }else{
            atack = this.strength-this.strength*0.2;
        }
        System.out.println(name+"使用徒手攻击造成"+atack+"点伤害");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getStrength() {
        return strength;
    }

    public void setStrength(double strength) {
        if(strength>999||strength<0){
            System.out.println("力量值非法,使用默认力量100");
            this.strength = 100;
        }else{
            this.strength = strength;
        }
    }

    public double getWit() {
        return wit;
    }

    public void setWit(double wit) {
        if(wit>300 || wit<0){
            System.out.println("智慧值非法,使用默认智慧值100");
        }else{
            this.wit = wit;
        }
    }

    public double getAgility() {
        return agility;
    }

    public void setAgility(double agility) {
        if(agility>200 || agility<0){
            System.out.println("敏捷值非法,使用默认敏捷值100");
        }else{
            this.agility = agility;
        }
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", strength=" + strength +
                ", wit=" + wit +
                ", agility=" + agility +
                '}';
    }
}
